<?
/**
 * setup.php
 *
 * <pre>
 * Devyra Internacionalnaya
 * Vebba PHP Framework and Website Builder
 * Setup program for new installation
 * </pre>
 *
 * @package   --
 * @version   0.7.0101 alpha
 * @since     2012
 * @author    Paul Dinh
 * @copyright Devyra Internacionalnaya
 */
require_once("classes/core/static/utils.php");
require_once("classes/core/static/xml.php");
$Reveal_Url = false; 

//get list of modules from config.xml
$Modules = array();
$Config  = xml::arr_from_file("config.xml");
$Temp    = $Config["modules"];
$Temp    = strtolower($Temp); //make module names be in lowercase
$Temp    = preg_replace("/[\s+]/","",$Temp); //remove all spaces
$Modules = explode(",",$Temp);

//path to index.php
$Script_Name = $_SERVER["SCRIPT_NAME"];
$Index_Php   = str_replace("setup.php","index.php",$Script_Name);

//first portion of the apache htaccess file
$Text1 = <<<HEREDOC
###
 # .htaccess
 # 
 # <pre>
 # Devyra Internacionalnaya
 # Vebba PHP Framework and Website Builder
 # Apache access file
 # </pre>
 ##
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^setup.php$ setup.php [L]

RewriteCond %{REQUEST_URI} !^##Index_Php1##
RewriteCond %{REQUEST_URI} !\.(css|html|js|gif|jpg|png|zip)$
RewriteRule ^(.*)$ ##Index_Php2##?$1 ##Flags##
HEREDOC;

//check if showing real url
if ($Reveal_Url)
  $Text1 = str_replace("##Flags##","[R,L]",$Text1);
else
  $Text1 = str_replace("##Flags##","[L]",$Text1);

//replacement into Text1
$Temp  = str_replace("index.php","index\\.php",$Index_Php);
$Text1 = str_replace("##Index_Php1##",$Temp,$Text1);
$Text1 = str_replace("##Index_Php2##",$Index_Php,$Text1);

//last portion of apache htaccess file
$Text2 = <<<HEREDOC
<Files config.xml>
  order allow,deny
  deny from all
</Files>
HEREDOC;

//join and write portions of htaccess file to file
$Text1 .= "\r\n\r\n";
$Combined_Text = $Text1.$Text2;
file_put_contents(".htaccess",$Combined_Text);

//show the setup status
echo "Website setup done successfully!";

//END-OF-FILE
